#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-13 8:59 上午
# @Author  : yangdy
# @File    : 2020-08-13.43.字符串相乘
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def multiply(self, num1: str, num2: str) -> str:
        ans = ''
        l1, l2 = len(num1), len(num2)
        mm = {}
        for i in range(10):
            for j in range(10):
                mm[f'{i}{j}'] = i * j

        data = [0 for i in range(l1+l2)]
        for i in range(l1):
            for j in range(l2):
                data[i+j] += mm[num1[l1-1-i]+num2[l2-1-j]]
        for i in range(l1+l2-1):
            data[i+1] += data[i] // 10
            data[i] %= 10
        ll = l1 + l2 - 1
        while ll > 0 and data[ll] == 0:
            ll -= 1
        ans = ''.join([str(data[i]) for i in range(ll, -1, -1)])
        return ans


questions = [
    ('2', '2',),
    ('123', '456',),
    ('999', '9999',),
    ('98', '9'),
    ('9133', '0',),
]

work(questions, lambda q: Solution().multiply(q[0], q[1]))
